package com.zsh.demo.controller;

import com.zsh.demo.pojo.MainMenu;
import com.zsh.demo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;
    @RequestMapping("/menu")
    public ResponseEntity menu(){
        Map<String,Object> map=new HashMap<>();
        List<MainMenu> list=menuService.getMenu();
        try {
            if (list != null) {
                map.put("list", list);
                map.put("flag",200);
            }
            return ResponseEntity.ok().body(map);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("程序错误");
        }
    }
}
